
package prettypenny;

import java.util.ArrayList;
import java.sql.*;
public class MechanicList {
  private ArrayList<Mechanic> mechanics; 
    private Connection con;
    private Statement stmt;
    private ResultSet rs;
    private int position;

   /* DB Struture
     * car: carId, make, model, fuelType, regNum, hireCar
     * carService: serviceID, clientId, carId, locationId, mechanicId, typeId, serviceDate, serviceTime, serviceDurationHour, description, price, bookingDate, mileage
     * client: clientId, forname, surname, dob, addLine1, addLine2, city, county, postcode, homeNum, mobileNum, email
     * location: locationId, branch
     * mechanic: mechanicId, forename, surname, mobNum
     * serviceType: typeId, typeOfService
     */

    
    public MechanicList() {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // server:port:database
            con = DriverManager.getConnection("jdbc:odbc:uni");
            stmt = con.createStatement();

            mechanics = new ArrayList<Mechanic>();
            rs = stmt.executeQuery("SELECT * FROM mechanic");
            int count = 0;
            while (rs.next()) {
                count++;
                mechanics.add(new Mechanic(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4)));
            }
        }catch(Exception ex) {
            System.out.println(ex.toString());
            
        }
    }

    public ArrayList getMechanics() {
        return this.mechanics;
    }

    public Mechanic getFirst() {
        position = 0;
        return mechanics.get(position);
    }

    public Mechanic getLast() {
        position = mechanics.size() - 1;
        return mechanics.get(position);
    }

    public Mechanic getNext() {
        if (position < mechanics.size()) {
            position++;
        }
        return mechanics.get(position);
    }

    public Mechanic getPosition(int value) {
        return mechanics.get(value-1);
    }

    public Mechanic getPrevious() {
        if (position > 0) {
            position--;
        }
        return mechanics.get(position);
    }

    public int getSize() {
        return mechanics.size() - 1;
    }
}
